﻿using GameControler.Emgu;
using GameControler.Game;
using PlatformCommon.Manager;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;

namespace GameControler
{
    public class ReturnMainView : ViewObject
    {

        public override string FloderName
        {
            get { return "ReturnMainView"; }
        }

        private static ReturnMainView instance;
        public static ReturnMainView Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new ReturnMainView();
                }
                return instance;
            }
        }

        public Point? ClickPoint
        {
            private set;
            get;
        }

        public override bool IsCurrentView(System.Drawing.Bitmap intputbmp)
        {
            var width = intputbmp.Width;
            var height = intputbmp.Height;
            foreach (var item in this.Templates)
            {
                var x = item.Point.X > 0 ? 0 : intputbmp.Width + item.Point.X;
                var y = item.Point.Y > 0 ? 0 : intputbmp.Height + item.Point.Y;
                var clipbitmap = intputbmp.Clone(new Rectangle(x, y, Math.Abs(item.Point.X), Math.Abs(item.Point.Y)), intputbmp.PixelFormat);
                var md = JilyEmgu.MatchAllResultRGB(clipbitmap, item, 1d);
             //   clipbitmap.Save(@"c:\11.png");
                var matchhsv = JilyEmgu.MatchResult(clipbitmap, item, 0.5);

                clipbitmap.Dispose();
                if ((item.Team == "1") == (md.IsMatch || matchhsv.IsMatch))
                {
                    ClickPoint = GameHelper.ReturnButtonPoint;
                    return true;
                }
            }

            return false;
        }
    }
}
